<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>敏感字符替换</title>
	<style>
		*{
			margin: 0;
			padding: 0;
		}
		.wrap{
			width: 500px;
			height: 500px;
			background-color: #ccc;
			margin:100px auto;
			font-size: 30px;
		}
		input{
			height: 40px;
		}
	</style>
</head>
<body>
	<div class="wrap">
		请输入敏感字符:<input type="text" id="input"><br>请用英文逗号隔开<br><br>
		请输入一段话:<textarea name="" id="textArea" cols="30" rows="10"></textarea><br>
	</div>
	<script>
	var input=document.getElementById('input');
	var area=document.getElementById('textArea');
	function getMinGanWord(){
		console.log(1)
		var val=input.value;
		var arr=val.split(",");
		var areaVal =area.value;
		var newStr="";
		console.log(arr)
		for (var i = 0; i < arr.length; i++) {
			if (i==0) {
				newStr=areaVal.replace(new RegExp(arr[i],"g"),"*");
			}
			newStr=newStr.replace(new RegExp(arr[i],"g"),"*")
		}

		area.value=newStr;
		console.log(newStr)
	}
	input.onblur=function(){
		getMinGanWord();
	}
	area.onchange=function(){
		getMinGanWord();
	}
	</script>
</body>
</html>